﻿using System.Linq;
using Daemon.Common;
using Daemon.Common.Helpers;
using Daemon.Infrustructure.EF;
using Daemon.Repository.EF.Enums;
using Daemon.Repository.Contract;
using Daemon.Model;
using System;
using System.Linq.Expressions;
using System.Collections.Generic;

namespace Daemon.Repository.EF
{
    public class PublicSharedRepository : Repository<PublicShared>, IPublicSharedRepository
    {
        protected override Expression<Func<PublicShared, int>> PrimaryKeyExpression => r => r.Id;

        public PublicSharedRepository(ApiDBContent context) : base(context)
        {
        }

        protected override void UpdateEntitiesBeforeCreate(IEnumerable<PublicShared> entities, ApiDBContent context)
        {
            foreach (var entity in entities)
            {
                entity.SharedUid = Guid.NewGuid().ToString();
                entity.BeginTime = DateTime.Now;
                entity.EndTime = DateTime.Now.AddDays(2);
                entity.UserId = AuthInfo.UserId;
            }
        }
    }
}
